<%@ page import="com.wiseMen.platform.support.security.UserUtils"%>
<%@ page import="org.apache.shiro.SecurityUtils"%>
<%@ page import="org.apache.shiro.subject.Subject"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.UUID"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
    
    Subject subject = SecurityUtils.getSubject();
    boolean hasLogined=false;
    if(subject!=null && subject.isAuthenticated()){
    	hasLogined=true;
    }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html class="fsvs demo"  xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<link rel="stylesheet" href="${root}/res/webpage/css/main2.css">
<script type="text/javascript" src="${root}/res/jsLib/wiseMen/workOrder/common.js"></script>
<%@ include file="/WEB-INF/pages/common/includeCoreCssJs.jsp"%>
<style type="text/css">
	.moreTr{
		display: none;
	}
</style>
<script type="text/javascript">
var currentUserId = '<%=UserUtils.getCurrendUser().getId()%>';
$(document).ready(function(){
	webUtils.nameSpace("wiseMen.workOrder");
	//样式效果JS
	var $card1_li = $('#card1 ul li');
	$card1_li.click(function(){
		$(this).addClass('selected').siblings().removeClass('selected');
		var index = $card1_li.index(this);
		//$('div.card1_box > div').eq(index).show().siblings().hide();
	    //刷新工单列表
	    if(index==0){
	    	$("input[name=sclzts]").val('-1,0,2');
	    }else{
	    	$("input[name=sclzts]").val('all');
	    }
	    iworkOrderGrid.bootstrapTable("refresh");
	});
	
	//设置类型选项
	var ywlx = $("select[name=ls_ywlx]");
	ywlx.change(function(){
		$("select[name=ls_zywlx]").find('option').hide().eq(0).show();
		$("select[name=ls_zywlx]").find('option[value*='+$(this).val()+'-]').show().eq(0).val();
		$("select[name=ls_zywlx]").val('');
	});
	$("select[name=ls_zywlx]").find('option').hide().eq(0).show();;
	$("select[name=ls_zywlx]").find('option[value*='+ywlx.val()+'-]').show();
	//设置选择日期事件
	$("input[name=ls_cjkssj],input[name=ls_cjjssj]").datetimepicker({
        	format: 'YYYY-MM-DD',
            locale: "zh-cn"
    });
	
	//高级检索按钮事件
	$("button[name=moreBtn]").click(function(){
		var parent = $(this).parent().parent();
		if($(this).attr("show")!='1'){
			parent.find(".moreTr").show();
			$(this).attr("show","1");
		}else{
			parent.find(".moreTr").hide();
			$(this).attr("show","0");
		}
	});
	
	//查找按钮事件
	$("button[name=queryBtn]").click(function(){
		iworkOrderGrid.bootstrapTable("refresh");
	});
	
	//初始化列表数据
	var uuid = '${uuid}';
	var _iworkOrderGridTB=$("#iWorkOrderTb_"+uuid);
    var iworkOrderGrid = $("#iWorkOrderGrid_"+uuid).bootstrapTable({
    	url:ctx + "/workOrderAct/queryWorkOrderDealList.do",
    	columns:[
			{field: '_id',checkbox:true},
			{title: '业务类型', field: 'YWLX',width: "130px",formatter:function(data, row, index){
            	return wo.getDataDicItemVal('YWLX', data);
            }},
            {title: '子业务类型', field: 'ZYWLX',width: "110px",formatter:function(data, row, index){
            	return wo.getDataDicItemVal('ZYWLX', data);
            }},
            {title: '来电号码', field: 'LDHM', width: "120px"},
            {title: '客户姓名', field: 'KHXM', width: "80px"},
            {title: '登记时间', field: 'CREATETIME',width: "160px",formatter:function(data, row, index){
            	return webUtils.parseTimestamp(data, 'yyyy-MM-dd HH:mm:ss');
            }},
            {title: '流转时间', field: 'HJSJ',width: "160px",formatter:function(data, row, index){
            	return webUtils.parseTimestamp(data, 'yyyy-MM-dd HH:mm:ss');
            }},
            {title: '当前环节', field: 'HJMC',width: "100px",formatter:function(data, row, index){
            	var html = '';
            	if(row.CXLX=='deal'){
	            	html = data;
	            	if(row.CLZT=='2'){
	            		html+='<font color="red" title="暂缓派单">(缓)</font>';
	            	}
	            	if(row.SFZT=='1'){
	            		html+='<font color="red" title="请求释放">(释)</font>';
	            	}
	            	if(row.CLZT=='-1'){
	            		html='暂存';
	            	}
            	}else{
            		if(row.HJZT=='0'){
            			html = row.DQHJ;
            		}else{
            			html = data?data:'暂存';
            		}
            	}
            	if(row.CQBJ=='1'){
            		html+='<font color="red" title="重启原因:'+wo.getDataDicItemVal('CQYY', row.CQYY)+'">(重)</font>';
            	}
            	return html;
            }},
            {title: '操作', field: 'ID',width: "140px",formatter:function(data, row, index){
            	var html ='';
            	if(row.CLZT=='-1'){
            		html+= '<button type="button" class="btn btn-primary btn-sm" title="修改" onclick="javascript:wiseMen.workOrder.mod('+index+');"><span class="glyphicon glyphicon-edit"></span></button> ';
            		html+= '<button type="button" class="btn btn-danger btn-sm" title="删除" onclick="javascript:wiseMen.workOrder.del('+index+');"><span class="glyphicon glyphicon-trash"></span></button> ';
            	}
            	if(row.CLZT=='0' || row.CLZT=='2'){
            		html+='<button type="button" class="btn btn-success btn-sm" title="处理" onclick="javascript:wiseMen.workOrder.deal('+index+');"><span class="glyphicon glyphicon-file"></span></button>';
            	}
            	if(html==''){
            		html+='<button type="button" class="btn btn-default btn-sm" title="查看" onclick="javascript:wiseMen.workOrder.query('+index+');"><span class="glyphicon glyphicon glyphicon-search"></span></button>';
            	}
            	return html;
            }}
    	],
	    queryParams: function(d) {
	    	d.clzts=$("input[name=sclzts]").val();
	    	
	        d.ldhm = $("input[name=ls_ldhm]").val();
	        d.yhzh = $("input[name=ls_yhzh]").val();
	        d.yjsjh = $("input[name=ls_yjsjh]").val();
	        d.khxm = $("input[name=ls_khxm]").val();
	        d.ywly = $("select[name=ls_ywly]").val();
	        d.khlx = $("select[name=ls_khlx]").val();
	        d.ywlx = $("select[name=ls_ywlx]").val();
	        d.zywlx = $("select[name=ls_zywlx]").val();
	        d.yh = $("select[name=ls_yh]").val();
	        d.kz = $("select[name=ls_kz]").val();
	        d.gdzt = $("select[name=ls_gdzt]").val();
	        
	        d.cjkssj = $("input[name=ls_cjkssj]").val();
	        d.cjjssj = $("input[name=ls_cjjssj]").val();
	        d.cjr = $("input[name=ls_cjr]").val();
	        d.dqclr = $("input[name=ls_dqclr]").val();
	        d.khsq = $("input[name=ls_khsq]").val();
	        d.slqk = $("input[name=ls_slqk]").val();
	        
	        return d;
	    }
    });
    //添加工单事件
    $("#addWorkOrder").click(function(){
    	var uuid=webUtils.uuid();
		var d=editIWrokOrder({
			winId:uuid,
			onremove:function(){
				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
			},
		});
		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
			iworkOrderGrid.bootstrapTable("refresh");
			d.close();
		},true);
    });
  	//修改工单事件
    wiseMen.workOrder.mod=function(rowIndex){
    	var uuid=webUtils.uuid();
    	var row=iworkOrderGrid.bootstrapTable("getRowByIndex", rowIndex);
   		var d=editIWrokOrder({
   			id:row.ID,
   			clid:row.CLID,
   			winId:uuid,
   			onremove:function(){
   				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
   			},
   		});
   		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
   			iworkOrderGrid.bootstrapTable("refresh");
   			d.close();
   		},true);
    }
    //处理工单事件
    wiseMen.workOrder.deal=function(rowIndex){
    	var uuid=webUtils.uuid();
    	var row=iworkOrderGrid.bootstrapTable("getRowByIndex", rowIndex);
   		var d=dealIWrokOrder({
   			id:row.ID,
			clid:row.CLID,
   			winId:uuid,
   			action:'deal',
   			onremove:function(){
   				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
   			},
   		});
   		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
   			iworkOrderGrid.bootstrapTable("refresh");
   			d.close();
   		},true);
    }
    //删除工单事件
    wiseMen.workOrder.del=function(rowIndex){
    	var row=iworkOrderGrid.bootstrapTable("getRowByIndex", rowIndex);
   		webUtils.confirm("删除后将不可恢复，请问是否继续?", function(result) {
			if(result){
				var selecteds = [row.ID];
                $.post(ctx + "/workOrderAct/delWorkOrder.do.do", {ids: row.ID}, function (data) {
                    if (data.success) {
                    	iworkOrderGrid.bootstrapTable("refresh");
                    } else {
                    	webUtils.alert(data.msg);
                    }
                }, 'json');
			}
   		});
    }
    //查看工单事件
    wiseMen.workOrder.query=function(rowIndex){
    	var uuid=webUtils.uuid();
    	var row=iworkOrderGrid.bootstrapTable("getRowByIndex", rowIndex);
   		var d=dealIWrokOrder({
   			id:row.ID,
			clid:row.CLID,
   			gdclzt:row.GDCLZT,
   			winId:uuid,
   			title:'查看工单',
   			action:'query',
   			onremove:function(){
   				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
   			},
   		});
   		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
   			iworkOrderGrid.bootstrapTable("refresh");
   			d.close();
   		},true);
    }
    //添加/修改窗口
    var editIWrokOrder=function(params){
        var url = "/workOrderAct/addWrokOrderView.do?";
    	params = params || {};
        var t = [];
        if (params.id) {
            t.push("id=" + params.id);
            url = "/workOrderAct/editWrokOrderView.do?";
        }
        if (params.clid) {
            t.push("clid=" + params.clid);
        }
        if (params.winId) {
            t.push("winId=" + params.winId);
        }
        var dialog=webUtils.dialog({
          	 title:'工单登记',
          	 url:ctx + url + t.join("&"),
          	 width:1250,
          	 height:$(this).height(),
          	 onremove:function () {
                   if (params.onremove) {
                       params.onremove.call(null);
                   }
              }
        });
        layer.full(dialog.dialog);
        return dialog;
    }
    //处理窗口
    var dealIWrokOrder=function(params){
    	params = params || {};
        var t = [];
        if (params.id) {
            t.push("id=" + params.id);
        }
        if (params.clid) {
            t.push("clid=" + params.clid);
        }
        if (params.gdclzt) {
            t.push("gdclzt=" + params.gdclzt);
        }
        if (params.winId) {
            t.push("winId=" + params.winId);
        }
        if (params.action) {
            t.push("action=" + params.action);
        }
        var dialog=webUtils.dialog({
          	 title:params.title?params.title:'工单处理',
          	 url:ctx + "/workOrderAct/dealWrokOrderView.do?" + t.join("&"),
          	 width:1250,
          	 height:$(this).height(),
          	 onremove:function () {
                   if (params.onremove) {
                       params.onremove.call(null);
                   }
              }
        });
        layer.full(dialog.dialog);
        return dialog;
    }
    //查看历史工单事件
    wiseMen.workOrder.queryHis=function(rowIndex){
    	var uuid=webUtils.uuid();
    	var row=wiseMen.workOrder.loadHisGrid.bootstrapTable("getRowByIndex", rowIndex);
   		var d=hisWrokOrder({
   			id:row.ID,
			clid:row.CLID,
   			gdclzt:row.GDCLZT,
   			winId:uuid,
   			title:'查看历史工单',
   			action:'his',
   			onremove:function(){
   				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
   			},
   		});
   		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
   			wiseMen.workOrder.loadHisGrid.bootstrapTable("refresh");
   			d.close();
   		},true);
    }
    //历史详细窗口
    var hisWrokOrder=function(params){
    	params = params || {};
        var t = [];
        if (params.id) {
            t.push("id=" + params.id);
        }
        if (params.clid) {
            t.push("clid=" + params.clid);
        }
        if (params.gdclzt) {
            t.push("gdclzt=" + params.gdclzt);
        }
        if (params.winId) {
            t.push("winId=" + params.winId);
        }
        var dialog=webUtils.dialog({
          	 title:params.title,
          	 url:ctx + "/workOrderAct/hisWrokOrderView.do?" + t.join("&"),
          	 width:1250,
          	 height:$(this).height(),
          	 onremove:function () {
                   if (params.onremove) {
                       params.onremove.call(null);
                   }
              }
        });
        layer.full(dialog.dialog);
        return dialog;
    }
});

window.onbeforeunload=function(){
	changeOnlineState(1);
}

$(function(){
	var currentUser;
	var hasLogin='<%=hasLogined%>'
	$("#loginDialogBt").click(function(){
		var r=webUtils.dialog({
			title:"用户登录",
			url:root+"/Login.jsp"
		});
	});
	
	$("#logoutBt").click(function(){
		changeOnlineState(1);
		window.location.href=ctx+"/logout.do"
	});
	
	if(hasLogin && hasLogin=='true'){
		$(".login").hide();
		$(".logout").show();
		
		currentUser=webUtils.getCurrentUser();
		if(currentUser){
			$("#userName").html(currentUser.userName);
		}
		
		changeOnlineState(2);
		updateGroupStr();
	}
	
	/*	切换在线离线状态	*/
	$("#toggleOnline").click(function(){
		var $this=$(this);
		if($this.data("onlinestate")==2){
			changeOnlineState(1);
		}else{
			changeOnlineState(2);
		}
	});
	
});

function changeOnlineState(state){
	var $this=$("#toggleOnline");
	var changeState=state;
	var changeStateStr=changeState==1?"离线":"在线";
	$.post(ctx+"/userAction/updateOnlineState.do",{state:changeState},function(d){
		if(d.success){
			$this.data("onlinestate",changeState)
			$(".onlineStateStr").html(changeStateStr);
		}else{
			webUtils.error(d.msg);
		}
	},"json");
}

function updateGroupStr(){
	$.getJSON(ctx+"/userGroupAct/loadUserGroups.do",function(gs){
		var strs=[];
		$.each(gs,function(gi,gn){
			strs.push(gn.title);
		});
		if(strs.length>0){
			$(".currentGroups").html(strs.join(","));
		}
	});
}
</script>
<body>
<div class="main">
	<div class="top">
    	<div class="top_left"><a href="#"><img width="350" src="${root}/res/webpage/images/logo.jpg" /></a></div>
    	<div class="top_right">
        	<p class="top_right_a1 login"><a href="javascript:void(0)" id="loginDialogBt">请点击登录</a></p>
        	<p class="top_right_a1 logout" style="display: none;">欢迎您，<a href="#" id="userName"></a>，<a href="javascript:void(0)" id="logoutBt">退出</a></p>
            <p class="top_right_a2"><span class="logout"  style="display: none;">您的工作组为：<span class="red currentGroups">未选择工作组</span>，您的状态为：<span class="red onlineStateStr">离线</span></span></p>
        </div>
    </div>
</div>
<div class="clear"></div>
    
<div class="nav_box">
    <ul id="nav"> 
        <li><a href="#" _fcksavedurl="#">DNA平台</a></li> 
        <li><a href="#" _fcksavedurl="#">插件平台</a></li> 
        <li><a href="#" _fcksavedurl="#">代收付平台</a> 
            <ul> 
                <li><a href="#" _fcksavedurl="#">代付查询</a></li> 
                <li><a href="#" _fcksavedurl="#">收款查询</a></li>
            </ul> 
        </li> 
    </ul> 
</div>

<div class="main">
	<input type="hidden" name="sclzts" value="-1,0,2"/>
    <div style="text-align:right; margin-top:10px;" id="addWorkOrder"><span class="i_btn_green1"><a href="#">新建工单</a></span></div>
    <div id="card1">
        <ul class="card1_menu">
            <li class="selected">我的代办工单</li>
            <li>全部工单</li>
        </ul>
    </div>
    <div class="card1_box">
        <!-- 我的代办工单 -->
        <div style="padding:20px 10px 20px 10px;">
            	<table class="s_tab1" border="0" cellspacing="0" cellpadding="0" id="queryTable">
	                <tr>
	                    <td width="100" class="s_tab1_tle">来电号码</td>
	                    <td width="150"><input id="callPhone" class="i_input1" style=" width:140px;" name="ls_ldhm" type="text" /></td>
	                    <td width="100" class="s_tab1_tle">银行账号</td>
	                    <td width="150"><input class="i_input1" style=" width:140px;" name="ls_yhzh" type="text" /></td>
	                    <td width="100" class="s_tab1_tle">交易手机号</td>
	                    <td width="150"><input class="i_input1" style=" width:140px;" name="ls_yjsjh" type="text" /></td>
	                    <td width="100" class="s_tab1_tle">开户姓名</td>
	                    <td width="150"><input class="i_input1" style=" width:140px;" name="ls_khxm" type="text" /></td>
	                </tr>
	                <tr>
	                    <td width="100" class="s_tab1_tle">业务来源</td>
	                    <td width="150">
	                    	<select class="i_select1" style=" width:140px;" name="ls_ywly">
	                    		<option value="">不限</option>
				                <pf:dataDic var="item" dicCode="YWLY">
				                    <option value="${item.value}">${item.name}</option>
				                </pf:dataDic>
				            </select>
	                    </td>
	                    <td width="100" class="s_tab1_tle">客户类型</td>
	                    <td width="150">
	                    	<select class="i_select1" style=" width:140px;" name="ls_khlx">
	                    		<option value="">不限</option>
				                <pf:dataDic var="item" dicCode="KHLX">
				                    <option value="${item.value}">${item.name}</option>
				                </pf:dataDic>
				            </select>
	                    </td>
	                    <td width="100" class="s_tab1_tle">业务类型</td>
	                    <td width="150">
	                    	<select class="i_select1" style=" width:140px;" name="ls_ywlx">
	                    		<option value="">不限</option>
	                      		<pf:dataDic var="item" dicCode="YWLX">
				                    <option value="${item.value}">${item.name}</option>
				                </pf:dataDic>
	                    	</select>
	                    </td>
	                    <td width="100" class="s_tab1_tle">业务子类型</td>
	                    <td width="150">
	                    	<select class="i_select1" style=" width:140px;" name="ls_zywlx">
	                    		<option value="">不限</option>
	                      		<pf:dataDic var="item" dicCode="ZYWLX">
				                    <option value="${item.value}">${item.name}</option>
				                </pf:dataDic>
	                    	</select>
	                    </td>
	                </tr>
	                <tr class="moreTr">
	                    <td width="100" class="s_tab1_tle">银行</td>
	                    <td width="150">
	                    	<select class="i_select1" style=" width:140px;" name="ls_yh">
	                    		<option value="">不限</option>
	                      		<pf:dataDic var="item" dicCode="YH">
				                    <option value="${item.value}">${item.name}</option>
				                </pf:dataDic>
	                    	</select>
	                    </td>
	                    <td width="100" class="s_tab1_tle">卡种</td>
	                    <td width="150">
	                    	<select class="i_select1" style=" width:140px;" name="ls_kz">
	                    		<option value="">不限</option>
	                      		<pf:dataDic var="item" dicCode="KZ">
				                    <option value="${item.value}">${item.name}</option>
				                </pf:dataDic>
	                    	</select>
	                    </td>
	                    <td width="100" class="s_tab1_tle">工单状态</td>
	                    <td width="150">
	                    	<select class="i_select1" style=" width:140px;" name="ls_gdzt">
	                    		<option value="">不限</option>
	                      		<pf:dataDic var="item" dicCode="GDHJ">
				                    <option value="${item.value}">${item.name}</option>
				                </pf:dataDic>
	                    	</select>
	                    </td>
	                    <td width="100" class="s_tab1_tle"></td>
	                    <td width="150">
	                    </td>
	                </tr>
	                <tr class="moreTr">
	                    <td width="100" class="s_tab1_tle">创建开始时间</td>
	                    <td width="150">
	                    	<input class="i_input1" style=" width:140px;" name="ls_cjkssj" type="text" />
	                    </td>
	                    <td width="100" class="s_tab1_tle">创建结束时间</td>
	                    <td width="150">
	                    	<input class="i_input1" style=" width:140px;" name="ls_cjjssj" type="text" />
	                    </td>
	                    <td width="100" class="s_tab1_tle">创建人</td>
	                    <td width="150">
	                    	<input class="i_input1" style=" width:140px;" name="ls_cjr" type="text" />
	                    </td>
	                    <td width="100" class="s_tab1_tle">当前处理人</td>
	                    <td width="150">
	                    	<input class="i_input1" style=" width:140px;" name="ls_dqclr" type="text" />
	                    </td>
	                </tr>
	                <tr class="moreTr">
	                    <td width="100" class="s_tab1_tle">客户诉求</td>
	                    <td width="150" colspan="3">
	                    	<input class="i_input1" style=" width:390px;" name="ls_khsq" type="text" />
	                    </td>
	                    <td width="100" class="s_tab1_tle">受理情况</td>
	                    <td width="150" colspan="3">
	                    	<input class="i_input1" style=" width:390px;" name="ls_slqk" type="text" />
	                    </td>
	                </tr>
                </table>
	            <div class="s_box1_btn">
	                <button type="button" class="btn btn-success" name="queryBtn">查询</button>
	                <button type="button" class="btn btn-danger" name="moreBtn">高级搜索</button>
	            </div>
        </div>
        <!-- 全部工单 -->
        <div style="padding:20px 20px 40px 20px;" class="hide">
        	
        </div>
    </div>
    
    <div class="box2">
    	<div class="box-body">
			<table id="iWorkOrderGrid_${uuid}" >
	   		</table>
		</div>
    </div>
    
</div>
<div class="clear" style="height:80px;"></div>

<div class="copyright">
	<div class="main">易联支付有限公司(C)版权所有   |    ICP证： 粤B2-20120038   |    B2-20110256   |    短消息号:[2012]00200-A011</div>
</div>
<div class="bottom2">
	<div class="main">
    	<div class="bottom_left"><a href="#"><img src="${root }/res/webpage/images/b_logo.jpg" /></a></div>
    	<div class="bottom_right">中国人民银行支付业务许可证号：Z2006444000010</div>
    </div>
</div>
<%@ include file="/WEB-INF/pages/common/includeUiScript.jsp"%>
</body>
</html>
<script type="text/javascript">
	function GetQueryString(name){
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]); return null;
	}
	var telPhone=GetQueryString("phone");
	if(null!=telPhone){
		$("#callPhone").val(telPhone);
		iworkOrderGrid.bootstrapTable("refresh");
	}
</script>